<?php
session_start();
if (isset($_SESSION["username"])) {
?>
    <?php require_once('common/header.php'); ?>
    <!--页面主要内容-->
 <main class="lyear-layout-content">
      <div class="container-fluid">
        <div class="row">
            <?php
            include_once("../untils/conn.php");
            mysqli_query($con, "set names utf8");
            if ($con) {
                if ($db) {
                    // 获取每周订单数据
                    $weeklyQuery = "SELECT COUNT(*) AS count FROM oder WHERE WEEKDAY(FROM_UNIXTIME(`time`)) BETWEEN 0 AND 6 GROUP BY WEEKDAY(FROM_UNIXTIME(`time`))";
                    $weeklyResult = mysqli_query($con, $weeklyQuery);
                    $weeklyData = array();
                    while ($row = mysqli_fetch_assoc($weeklyResult)) {
                        $weeklyData[] = $row['count'];
                        
                        // echo $weeklyData;
                    }
            
                    // 获取每月订单数据
                    $monthlyQuery = "SELECT COUNT(*) AS count FROM oder WHERE MONTH(FROM_UNIXTIME(`time`)) BETWEEN 1 AND 12 GROUP BY MONTH(FROM_UNIXTIME(`time`))";
                    $monthlyResult = mysqli_query($con, $monthlyQuery);
                    $monthlyData = array();
                    while ($row = mysqli_fetch_assoc($monthlyResult)) {
                        $monthlyData[] = $row['count'];
                    }
            
                    // 其他查询代码保持不变
                    $sortsql = "select count(*) from oder";
                    $sortdata = mysqli_query($con, $sortsql);
                    $sortresult = mysqli_fetch_row($sortdata);
                    $listsql = "select count(*) from list";
                    $listdata = mysqli_query($con, $listsql);
                    $listresult = mysqli_fetch_row($listdata);
                    $sql = "select * from list  limit 0,8";
                    $data = mysqli_query($con, $sql);
                    $totalPrice = "SELECT SUM(price) AS total FROM oder WHERE card_sta = 1";
                    $totalData = mysqli_query($con, $totalPrice);
                    $totalResult = mysqli_fetch_assoc($totalData);
                    $sum = $totalResult['total'];
            
                    //返佣金额
                    $proxy_price_sql = "SELECT SUM(proxy_prices) AS total FROM revenue WHERE type = 0 AND state = 2";
                    $proxy_price_data = mysqli_query($con, $proxy_price_sql);
                    $proxy_price_result = mysqli_fetch_assoc($proxy_price_data);
                    $proxy_price_sum = $proxy_price_result['total'];
                }
            }
            ?>
          <div class="col-sm-6 col-lg-3">
            <div class="card bg-primary">
              <div class="card-body clearfix">
                <div class="pull-right">
                  <p class="h6 text-white m-t-0">平台收益</p>
                  <p class="h3 text-white m-b-0 fa-1-5x">￥<?php echo $sum ?></p>
                </div>
                <div class="pull-left"> <span class="img-avatar img-avatar-48 bg-translucent"><i class="mdi mdi-currency-cny fa-1-5x"></i></span> </div>
              </div>
            </div>
          </div>
          
          <div class="col-sm-6 col-lg-3">
            <div class="card bg-danger">
              <div class="card-body clearfix">
                <div class="pull-right">
                  <p class="h6 text-white m-t-0">订单总数</p>
                  <p class="h3 text-white m-b-0 fa-1-5x"><?php echo $sortresult[0] ?></p>
                </div>
                <div class="pull-left"> <span class="img-avatar img-avatar-48 bg-translucent"><i class="mdi mdi mdi-cube fa-1-5x"></i></span> </div>
              </div>
            </div>
          </div>
          
          <div class="col-sm-6 col-lg-3">
            <div class="card bg-success">
              <div class="card-body clearfix">
                <div class="pull-right">
                  <p class="h6 text-white m-t-0">产品总数</p>
                  <p class="h3 text-white m-b-0 fa-1-5x"><?php echo $listresult[0] ?></p>
                </div>
                <div class="pull-left"> <span class="img-avatar img-avatar-48 bg-translucent"><i class="mdi mdi-dns fa-1-5x"></i></span> </div>
              </div>
            </div>
          </div>
          
          <div class="col-sm-6 col-lg-3">
            <div class="card bg-info">
              <div class="card-body clearfix">
                <div class="pull-right">
                  <p class="h6 text-white m-t-0">已返佣金</p>
                  <p class="h3 text-white m-b-0 fa-1-5x"><?php echo $proxy_price_sum ?></p>
                </div>
                <div class="pull-left"> <span class="img-avatar img-avatar-48 bg-translucent"><i class="mdi mdi-coin fa-1-5x"></i></span> </div>
              </div>
            </div>
          </div>
        </div>
        
        <div class="row">
          
          <div class="col-lg-6"> 
            <div class="card">
              <div class="card-header">
                <h4>每周订单</h4>
              </div>
              <div class="card-body">
                <canvas class="js-chartjs-bars"></canvas>
              </div>
            </div>
          </div>
          
          <div class="col-lg-6"> 
            <div class="card">
              <div class="card-header">
                <h4>成交记录</h4>
              </div>
              <div class="card-body">
                <canvas class="js-chartjs-lines"></canvas>
              </div>
            </div>
          </div>
           
        </div>
        
     <div class="row">

                <div class="col-lg-12">
                    <div class="card">
                        <div class="card-header">
                            <h4>产品列表</h4>
                        </div>
                        <div class="card-body">
                            <div class="table-responsive">
                                <table class="table table-hover">
                                    <thead>
                                        <tr>
                                            <th>#</th>
                                            <th>产品名称</th>
                                            <th>包邮方式</th>
                                            <th>优惠时长</th>
                                            <th>产品分类</th>
                                            <th>产品标签</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php
                                        while ($row = mysqli_fetch_array($data)) {
                                        ?>
                                            <tr>
                                                <td><?php echo $row["id"] ?></td>
                                                <td><?php echo $row["name"] ?></td>
                                                <td><?php echo $row["baoyou"] ?></td>
                                                <td><?php echo $row["ltime"] ?></td>
                                                <td><?php echo $row["yys"] ?></td>
                                                <td>
                                                    <?php echo $row["gsd"] ?>
                                                </td>
                                            </tr>
                                        <?php
                                        }
                                        ?>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
        
      </div>
      
    </main>
    </main>
    <!--End 页面主要内容-->
    <?php require_once('common/footer.php'); ?>
<?php
} else {
    echo "<script>alert('您尚未登录，没有权限访问该页面');location.href='login.php';</script>";
}
?>